This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(tidyverse)
covid19 <- read_csv("data/covid19-daily-cases.csv")
Parsed with column specification:
cols(
country_region = [31mcol_character()[39m,
date = [34mcol_date(format = "")[39m,
confirmed = [32mcol_double()[39m
)
covid19
covid19 %>%
ggplot(aes(
x = date,
y = confirmed,
colour = country_region)) +
geom_line() +
guides(colour = FALSE)
Fit with log scale because then its normal
covid19 %>%
ggplot(aes(
x = date,
y = log10(confirmed),
colour = country_region)) +
geom_line() +
guides(colour = FALSE)
covid19 %>%
ggplot(aes(
x = date,
y = confirmed,
colour = country_region)) +
geom_line() +
guides(colour = FALSE) +
scale_y_log10()
covid19_rel <- covid19 %>%
group_by(country_region) %>%
mutate(days = as.numeric(date - min(date))) %>%
ungroup()
covid19_rel
covid19_rel %>%
ggplot(aes(
x = days,
y = confirmed,
colour = country_region)) +
geom_line() +
scale_y_log10() +
guides(colour = FALSE)
covid19_nz <- covid19_rel %>%
filter(country_region == "New Zealand")
p_nz <- covid19_rel %>%
ggplot(aes(x = days, y = confirmed,
group = country_region)) +
geom_line(colour = "grey", alpha = 0.5) +
geom_line(colour = "#238b45", size = 1, data = covid19_nz) +
scale_y_log10() +
guides(colour = FALSE)
p_nz
p_nz <- p_nz +
geom_label(aes(
x = max(days), y = max(confirmed),
label = country_region), data = covid19_nz,
colour = "#238b45", nudge_x = 3, nudge_y = .5)
p_nz
p_nz <- p_nz +
scale_y_log10(labels = scales::label_comma()) +
xlim(c(0, 100))
Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
p_nz
p_nz <- p_nz +
labs(
x = "Days since March 1",
y = "Confirmed cases (on log10)",
title = "Worldwide coronavirus confirmed cases",
subtitle = "highlighting New Zealand",
caption = "Data source: John Hopkins University, CSSE"
)
p_nz
library(plotly)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: 㤼㸱plotly㤼㸲
The following object is masked from 㤼㸱package:ggplot2㤼㸲:
last_plot
The following object is masked from 㤼㸱package:stats㤼㸲:
filter
The following object is masked from 㤼㸱package:graphics㤼㸲:
layout
ggplotly(p_nz)
Transformation introduced infinite values in continuous y-axisgeom_GeomLabel() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues